package com.lc.app.androidfirst;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.DisplayMetrics;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.lc.app.androidfirst.userdefine.view.PlaneView;

public class PlaneGameActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

  //      PlaneGameActivity.this.requestWindowFeature(Window.FEATURE_NO_TITLE);

        //full screen
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        final PlaneView planeView = new PlaneView(this);

        setContentView(planeView);
        planeView.setBackgroundResource(R.drawable.image_yellow);

        WindowManager manager = getWindowManager();
        DisplayMetrics display = this.getResources().getDisplayMetrics();
        int screenWidth = display.widthPixels;
        int screenHeight = display.heightPixels;

//        Display display = manager.getDefaultDisplay();
//        int screenWidth = display.getWidth();
//        int screenHeight = display.getHeight();

        planeView.currentX = screenWidth/2;
        planeView.currentY = screenHeight - 140;

        planeView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                float mX = event.getX();
                float mY = event.getY();

                planeView.currentX = mX;
                planeView.currentY = mY;

                planeView.invalidate();

                return true;
            }
        });
    }
}
